package de.teamgamma.cansat.groundstation.main;


import de.szut.gui.language.Languages;
import de.szut.gui.language.TranslatableComponent;
import de.szut.gui.language.TranslatableStyledButton;
import de.teamgamma.cansat.groundstation.control.Controller;
import de.teamgamma.cansat.groundstation.export.ExportPanel;
import de.teamgamma.cansat.groundstation.livestream.LivestreamPanel;
import de.teamgamma.cansat.groundstation.options.OptionPanel;









import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Panel of the main-menu
 * @author Marc Huisinga
 *
 */

public class MainMenuPanel extends DefaultPanel {
	/**
	 * Key of the livestream-button
	 */
	public static final String LIVESTREAMKEY = "livestream";
	/**
	 * Key of the export-button
	 */
	public static final String EXPORTKEY = "export";
	/**
	 * Key of the options-button
	 */
	public static final String OPTIONSKEY = "options";
	/**
	 * Width of each button on the panel
	 */
	public static final int BUTTONWIDTH = 280;
	/**
	 * Height of each button on the panel
	 */
	public static final int BUTTONHEIGHT = 25;
	/**
	 * Y-Position where the button-generation is started
	 */
	public static final int STARTPOSITIONY = 100;
	/**
	 * X-Position where the button-generation is started
	 */
	public static final int STARTPOSITIONX = Controller.getInstance().getGuiController().getMainFrame().getWidth()/2-BUTTONWIDTH/2+5;
	/**
	 * Y-Offset between the generated buttons
	 */
	public static final int OFFSETY = 60;
	/**
	 * All buttons for menu selection on the panel
	 */
	public static final ArrayList<String> SELECTIONBUTTONS = new ArrayList<String>();
	static {
		SELECTIONBUTTONS.add(LIVESTREAMKEY);
		SELECTIONBUTTONS.add(EXPORTKEY);
		SELECTIONBUTTONS.add(OPTIONSKEY);
	}
	
	
	private static final long serialVersionUID = -6321757896026656492L;
	private ArrayList<TranslatableComponent> translatableComponents;
	private HashMap<String, TranslatableStyledButton> selectionButtons;
	
	public MainMenuPanel() {
		translatableComponents = new ArrayList<TranslatableComponent>();
		selectionButtons = new HashMap<String, TranslatableStyledButton>();
	
		Languages.prepareComponent("mainmenu.MainMenuPanel.header", getHeader(), translatableComponents);
		
		Languages.prepareComponent("mainmenu.MainMenuPanel.exit", getReturnButton(), translatableComponents);
		getReturnButton().addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Controller.getInstance().getGuiController().closeMainFrame();
			}
		});
		
		int currentYPos = STARTPOSITIONY;
		
		for (String currentSelectionKey : SELECTIONBUTTONS) {
			TranslatableStyledButton currentButton = new TranslatableStyledButton();
			selectionButtons.put(currentSelectionKey, currentButton);
			Languages.prepareComponent("mainmenu.MainMenuPanel." + currentSelectionKey.toLowerCase(), currentButton, translatableComponents);
			currentButton.setBounds(STARTPOSITIONX,currentYPos, BUTTONWIDTH, BUTTONHEIGHT);
			add(currentButton);
			currentYPos += OFFSETY;
		}
		
		selectionButtons.get(LIVESTREAMKEY).addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				Controller.getInstance().getGuiController().toggleCurrentPanel(new LivestreamPanel());
			}
			
		});
		
		selectionButtons.get(EXPORTKEY).addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				Controller.getInstance().getGuiController().toggleCurrentPanel(new ExportPanel());
			}
			
		});
		
		selectionButtons.get(OPTIONSKEY).addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				Controller.getInstance().getGuiController().toggleCurrentPanel(new OptionPanel());
			}
			
		});
		
		Controller.getInstance().getGuiController().getLanguages().translateListOfComponents(translatableComponents);

	}
}
